package com.example.itemtouchhelperdemo.util;

import android.graphics.Bitmap;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.util.Util;

/**
 * 描述：用于管理图片加载
 */
public class ImageLoadUtils {


    /**
     * 加载图片
     *
     * @param imageUrl
     * @param imageView
     * @param requestOptions
     */
    public static void loadImageWithTransForm(String imageUrl, ImageView imageView, RequestOptions requestOptions) {
        if (Util.isOnMainThread()) {
            Glide.with(imageView).load(imageUrl)
                    .apply(requestOptions)
                    .into(imageView);
        }
    }

    /**
     * 加载图片
     *
     * @param res
     * @param imageView
     * @param requestOptions
     */
    public static void loadImageWithTransForm(int res, ImageView imageView, RequestOptions requestOptions) {
        if (Util.isOnMainThread()) {
            Glide.with(imageView).load(res)
                    .apply(requestOptions)
                    .into(imageView);
        }
    }

    //加载图片地址(圆角)
    public static void loadImageRoundedTransForm(int res, ImageView imageView, int radius) {
        if (Util.isOnMainThread()) {
            Glide.with(imageView).load(res)
                    .apply(new RequestOptions()
                            .transform(new MultiTransformation(new CenterCrop(), new RoundedCorners(radius))))
                    .into(imageView);
        }
    }

    //加载图片地址(圆角)
    public static void loadImageRoundedTransForm(Bitmap bitmap, ImageView imageView, int radius) {
        if (Util.isOnMainThread()) {
            Glide.with(imageView).load(bitmap)
                    .apply(new RequestOptions()
                            .transform(new MultiTransformation(new CenterCrop(), new RoundedCorners(radius))))
                    .into(imageView);
        }
    }
}
